package com.itcat.interceptor;

import com.itcat.mysql.pojo.UmsAdmin;

/**
 * [工具类：实现向threadlocal存储数据的方法]
 *
 * @author : [Cr Mr]
 * @version : [v1.0]
 * @date : [2022/3/16 20:01]
 */
public class UserHolder {
    private static ThreadLocal<UmsAdmin> tl = new ThreadLocal<>();

    //将用户对象存入ThreadLocal
    public static void set(UmsAdmin umsAdmin) {
        tl.set(umsAdmin);
    }

    //从当前线程，获取用户对象
    public static UmsAdmin get() {
        return tl.get();
    }

    //从当前线程，获取用户对象的id
    public static Long getUserId() {
        return tl.get().getId();
    }

    public static String getUsername() {
        return tl.get().getUsername();
    }

    public static void remove() {
        tl.remove();
    }
}
